{literal}
<script type="text/javascript">

var map;
function onLoad() {
	map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
   
{/literal}
        {if $incident_post.lat and $incident_post.lon}
            map.setCenter(new GLatLng({$incident_post.lat}, {$incident_post.lon}), 12);
            var point = new GLatLng({$incident_post.lat}, {$incident_post.lon});
            var marker = new GMarker(point);
            map.addOverlay(marker);
        {else}
	    map.setCenter(new GLatLng(58.897552, 5.675125), 12);
        {/if}
{literal}
	var marker;
        GEvent.addListener(map, "click", function(overlay, point) {
            if (marker) {
                map.removeOverlay(marker);
                document.incident.lon.value = null;
                document.incident.lat.value = null;
                marker = null;
                return;
            }
            marker = new GMarker(point);
            map.addOverlay(marker);
            document.incident.lon.value = point.x;
            document.incident.lat.value = point.y;
            

           /* 
		if (overlay) {
                    alert("kommer hit");
			map.removeOverlay(overlay);
			document.incident.lon.value = 0;
			document.incident.lat.value = 0;
		}
 		else {
                    if (!marker) return;
			map.removeOverlay(marker);
			marker = new GMarker(point);
			map.addOverlay(marker);
			document.incident.lon.value=point.x;
			document.incident.lat.value=point.y;
		}*/
        });
 }

function center_map(array) {
	//alert(array);
	point = new GLatLng(array[0], array[1]);
	map.setCenter(point);
}
</script>
{/literal}
